package com.emn.fil.automaticdiscover.ihm;

import java.awt.Component;
import java.awt.Container;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.FocusTraversalPolicy;
import java.util.Iterator;
import java.util.Vector;

class FocusPolicy extends FocusTraversalPolicy {
	private Vector components;

	private int index;

	public FocusPolicy() {
		super();
		components = new Vector();
		index = 0;
	}

	public void addComponent(Component c) {
		components.addElement(c);
	}

	public Component getFirstComponent() {
		index = 0;
		return (Component) components.elementAt(index);
	}

	public Component getComponentAfter(Container c, Component comp) {
		Iterator iter = components.iterator();
		boolean found = false;
		while (!found && iter.hasNext()) {
			Component test = (Component) iter.next();
			found = (test == comp);
		}
		if (iter.hasNext())
			return (Component) iter.next();
		else
			return getFirstComponent();
	}

	public Component getLastComponent(Container c) {
		int i = components.size() - 1;
		if (i >= 0) {
			return (Component) components.elementAt(i);
		} else
			return null;
	}

	public Component getComponentBefore(Container c, Component comp) {
		int i = 0;
		boolean found = false;
		while (!found && i < components.size()) {
			Component test = (Component) components.elementAt(i);
			found = (test == comp);
		}
		if (i > 0)
			return (Component) components.elementAt(i - 1);
		else
			return getLastComponent(null);
	}

	@Override
	public Component getDefaultComponent(Container aContainer) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Component getFirstComponent(Container aContainer) {
		// TODO Auto-generated method stub
		return null;
	}
}
